﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;

namespace Relay.UI.Controls.Docking.Primitives {
    internal class DockManagerOverlayAdorner : Adorner {
        #region Fields
        private DockManagerOverlay _overlay = null;
        #endregion

        #region Constructor
        public DockManagerOverlayAdorner(UIElement element) : base(element) {
            if (!(element is DockManager))
                throw new ArgumentException("element must be a DockManager", "element");
            SnapsToDevicePixels = true;

            DockManager owner = element as DockManager;
            _overlay = new DockManagerOverlay();
            _overlay.Width = owner.ActualWidth;
            _overlay.Height = owner.ActualHeight;

            AddVisualChild(_overlay);
        }
        #endregion

        #region Properties
        public DockManagerOverlay DockOverlay {
            get { return _overlay; }
        }
        #endregion

        #region Overrides
        protected override Visual GetVisualChild(int index) {
            if (index != 0) throw new ArgumentOutOfRangeException("index");
            return _overlay;
        }

        protected override int VisualChildrenCount {
            get {
                return 1;
            }
        }

        protected override Size ArrangeOverride(Size finalSize) {
            Rect placementRect = new Rect();
            placementRect.X = (finalSize.Width - _overlay.Width) / 2;
            placementRect.Y = (finalSize.Height - _overlay.Height) / 2;
            placementRect.Width = _overlay.Width;
            placementRect.Height = _overlay.Height;

            _overlay.Arrange(placementRect);
            return finalSize;
        }
        #endregion
    }
}
